package com.kyxx.mycommonproject.base;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.kyxx.mycommonproject.R;
import com.kyxx.mycommonproject.utils.ToastUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.lang.reflect.Field;

/**
 * Created by Administrator on 2016/9/8.
 */
public abstract class BaseActivity0 extends AppCompatActivity {
    protected Context context;
    protected ImageLoader imageLoader;
    protected DisplayImageOptions options = null;
    protected Toolbar toolbar;
    protected TextView tv_title;
    protected ImageView iv_left;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getApplicationContext();
        imageLoader = ImageLoader.getInstance();
        options = new DisplayImageOptions.Builder().cacheInMemory(true)
                .cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build();
        initView();
    }

    private void initView() {
        loadViewLayout();
        findViewById();
        setListener();
        processLogic();
    }

    protected void loadToolBar(String title) {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        tv_title = (TextView) findViewById(R.id.tv_title);
        iv_left=(ImageView) findViewById(R.id.iv_left);
        toolbar.setTitle("");
        if (tv_title != null)
            tv_title.setText(title);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
//        iv_left.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                onBackPressed();
//            }
//        });
    }

    /**
     * @author txiuqi
     * @描述 加载布局文件
     */
    protected abstract void loadViewLayout();

    /**
     * @描述 根据ID查找控件
     */
    protected abstract void findViewById();

    /**
     * @描述 设置监听
     */
    protected abstract void setListener();

    /**
     * @描述 处理业务
     */
    protected abstract void processLogic();

    public void showToast(String msg) {
        ToastUtils.show(this, msg);
    }

    public void startActivity(Class target) {
        Intent intent = new Intent(this, target);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

}
